using ASP;
using HoWave.Common;
using HoWave.Data;
using HoWave.Web;
using HoWave.Web.Admin;
using System;
using System.Data;
using System.IO;
using System.Web;
using System.Web.Profile;
using System.Web.SessionState;
using System.Web.UI.WebControls;
public class HL_Admin_Admin_Shop : Admin, IRequiresSessionState
{
	private Shop_Shop _Shop = null;
	public string s_Class = "";
	public string s_QuickName = "";
	public string s_DetailType = "";
	public string s_DetailName = "";
	public bool m_tag = true;
	private string WhereStr = "";
	private string OrderbyStr = "";
	private string linkHead = "";
	protected DropDownList QuickSearch;
	protected DropDownList ShopSearchClass;
	protected DropDownList DetailSearchType;
	protected TextBox DetailSearchName;
	protected Button SearchButton;
	protected GridView GridView1;
	protected Label PagePanel;
	protected Button UpdateShopProductNumBtn;
	protected Button UpdateShoTemplate;
	protected Button DeleteBtn;
	protected Button Close_Button;
	protected Button OpenShop_Button;
	protected Button IdentifyShop_Button;
	protected Button NoIdentifyShop_Button;
	protected Button IsElite_Button;
	protected Button NoIsElite_Button;
	protected Shop_Shop m_Shop
	{
		get
		{
			Shop_Shop shop;
			if (this._Shop == null)
			{
				this._Shop = new Shop_Shop(this.conn);
				shop = this._Shop;
			}
			else
			{
				shop = this._Shop;
			}
			return shop;
		}
	}
	protected DefaultProfile Profile
	{
		get
		{
			return (DefaultProfile)this.Context.Profile;
		}
	}
	protected global_asax ApplicationInstance
	{
		get
		{
			return (global_asax)this.Context.ApplicationInstance;
		}
	}
	protected void Page_Load(object sender, EventArgs e)
	{
		if (!base.admin.CheckAdminPower(17))
		{
			base.WriteLog("View", Language.GetAdminMsg("Log/Access", "0"), "Shop");
			base.WriteRightErrMsg();
		}
		if (!base.IsPostBack)
		{
			this.BindClassDownList();
			this.BindList();
		}
	}
	protected void BindClassDownList()
	{
		Shop_Class shop_Class = new Shop_Class(this.conn);
		this.ShopSearchClass.DataSource = shop_Class.GetRootClass();
		this.ShopSearchClass.DataBind();
	}
	protected void QuickSearch_SelectedIndexChanged(object sender, EventArgs e)
	{
		this.m_tag = false;
		this.BindList();
	}
	protected void SearchButton_Click(object sender, EventArgs e)
	{
		this.m_tag = false;
		this.BindList();
	}
	protected void ShopSearchClass_SelectedIndexChanged(object sender, EventArgs e)
	{
		this.m_tag = false;
		this.BindList();
	}
	protected void ShopButtonOnCommon(object sender, CommandEventArgs e)
	{
		bool flag = false;
		string commandName = e.CommandName;
		switch (commandName)
		{
		case "Delete":
			if (base.admin.CheckAdminPower(17))
			{
				flag = true;
			}
			break;
		case "Close":
			if (base.admin.CheckAdminPower(17))
			{
				flag = true;
			}
			break;
		case "OpenShop":
			if (base.admin.CheckAdminPower(17))
			{
				flag = true;
			}
			break;
		case "IdentifyShop":
			if (base.admin.CheckAdminPower(17))
			{
				flag = true;
			}
			break;
		case "NoIdentifyShop":
			if (base.admin.CheckAdminPower(17))
			{
				flag = true;
			}
			break;
		case "IsElite":
			if (base.admin.CheckAdminPower(17))
			{
				flag = true;
			}
			break;
		case "NoIsElite":
			if (base.admin.CheckAdminPower(17))
			{
				flag = true;
			}
			break;
		}
		if (flag)
		{
			string text = base.Request["chk_select"];
			if (!string.IsNullOrEmpty(text))
			{
				this.m_Shop.EditShopByShopID(text, e.CommandName.ToString());
				base.WriteLog("Check", Language.GetAdminMsg("Log/ObjectID", text), "Shop");
				this.m_tag = false;
				this.BindList();
			}
		}
		else
		{
			base.WriteLog("Check", Language.GetAdminMsg("Log/Access", "0"), "Shop");
			base.WriteRightErrMsg();
		}
	}
	protected void BindList()
	{
		int num = Fetch.GetID("page");
		if (num == 0)
		{
			num = 1;
		}
		this.GetQuestString();
		int pagesize = 15;
		if (this.GridView1.PageSize != 0)
		{
			pagesize = int.Parse(this.GridView1.PageSize.ToString());
		}
		this.GridView1.DataSource = this.m_Shop.GetAllShop(num, this.WhereStr, this.OrderbyStr, pagesize);
		this.GridView1.DataBind();
		this.PagePanel.Text = this.m_Shop.GetPagePanel(this.linkHead);
	}
	protected void GetQuestString()
	{
		this.s_QuickName = Fetch.Get("s_QuickName");
		if (this.s_QuickName != string.Empty && this.m_tag)
		{
			if (this.s_QuickName != "all")
			{
				this.linkHead = this.linkHead + "&s_QuickName=" + this.s_QuickName;
				this.QuickSearch.SelectedValue = this.s_QuickName;
			}
		}
		else
		{
			this.s_QuickName = this.QuickSearch.SelectedValue.ToString();
			if (this.s_QuickName != "all")
			{
				this.linkHead = this.linkHead + "&s_QuickName=" + this.s_QuickName;
			}
		}
		this.s_Class = Fetch.Get("s_Class");
		if (this.s_Class != string.Empty && this.m_tag)
		{
			if (this.s_Class != "-1")
			{
				this.WhereStr = this.WhereStr + "and ShopCategoryID=" + this.s_Class + " ";
				this.linkHead = this.linkHead + "&s_Class=" + this.s_Class;
				this.ShopSearchClass.SelectedValue = this.s_Class;
			}
		}
		else
		{
			this.s_Class = this.ShopSearchClass.SelectedValue.ToString();
			if (this.s_Class != "-1")
			{
				this.WhereStr = this.WhereStr + "and ShopCategoryID=" + this.s_Class + " ";
				this.linkHead = this.linkHead + "&s_Class=" + this.s_Class;
			}
		}
		this.s_DetailType = Fetch.Get("s_DetailType");
		if (this.s_DetailType != string.Empty && this.m_tag)
		{
			this.DetailSearchType.SelectedValue = this.s_DetailType;
		}
		else
		{
			this.s_DetailType = this.DetailSearchType.SelectedValue.ToString();
		}
		if (this.s_DetailType != "")
		{
			this.s_DetailName = Fetch.Get("s_DetailName");
			if (this.s_DetailName != string.Empty && this.m_tag)
			{
				this.DetailSearchName.Text = this.s_DetailName;
			}
			else
			{
				this.s_DetailName = this.DetailSearchName.Text;
			}
			if (this.s_DetailName != string.Empty)
			{
				string text = this.s_DetailType;
				if (text != null)
				{
					if (text == "shop_name")
					{
						this.WhereStr = this.WhereStr + "and ShopName like '%" + this.s_DetailName + "%' ";
						goto IL_3D6;
					}
					if (text == "saler_name")
					{
						this.WhereStr = this.WhereStr + "and ShopOwnerName like '%" + this.s_DetailName + "%' ";
						goto IL_3D6;
					}
					if (text == "operate_item")
					{
						this.WhereStr = this.WhereStr + "and ShopOperatorItem like '%" + this.s_DetailName + "%' ";
						goto IL_3D6;
					}
				}
				this.WhereStr = this.WhereStr + "and ShopName like '%" + this.s_DetailName + "%' ";
				IL_3D6:
				string text2 = this.linkHead;
				this.linkHead = string.Concat(new string[]
				{
					text2,
					"&s_DetailType=",
					this.s_DetailType,
					"&s_DetailName=",
					base.Server.UrlEncode(this.s_DetailName)
				});
			}
		}
		if (this.s_QuickName != "all" && this.s_QuickName != string.Empty)
		{
			string text = this.s_QuickName;
			if (text != null)
			{
				if (!(text == "close"))
				{
					if (!(text == "normal"))
					{
						if (!(text == "pause"))
						{
							if (!(text == "three_day_open"))
							{
								if (text == "more_then_ten")
								{
									this.WhereStr += "and (select count(ProductID) from [HLShop_Product] Where HLShop_Product.ShopID=HLShop_Shop.ShopID)>10 ";
								}
							}
							else
							{
								this.WhereStr += "and datediff(d, ShopRegDate, getDate())<=3 ";
							}
						}
						else
						{
							this.WhereStr += "and ShopStatus=0 ";
						}
					}
					else
					{
						this.WhereStr += "and ShopStatus=1 ";
					}
				}
				else
				{
					this.WhereStr += "and ShopStatus=-1 ";
				}
			}
		}
		SiteConfigBll siteConfigBll = new SiteConfigBll();
		if (siteConfigBll.GetSiteString("SiteConfigInfo/CityArea") != "0")
		{
			if (HttpContext.Current.Request.Cookies["Howave_CityArea"] != null)
			{
				string str = HttpUtility.UrlDecode(HttpContext.Current.Request.Cookies["Howave_CityArea"].Value);
				this.WhereStr = this.WhereStr + "and ShopAddress like '%" + str + "%'";
			}
			else
			{
				if (HttpContext.Current.Request.Cookies["Howave_ProvinceArea"] != null)
				{
					string str2 = HttpUtility.UrlDecode(HttpContext.Current.Request.Cookies["Howave_ProvinceArea"].Value);
					this.WhereStr = this.WhereStr + "and ShopAddress like '%" + str2 + "%'";
				}
			}
		}
		if (this.WhereStr != "")
		{
			this.WhereStr = "and" + this.WhereStr;
			this.WhereStr = this.WhereStr.Replace("andand", "Where");
		}
	}
	protected void GridView1_RowDataBound(object sender, GridViewRowEventArgs e)
	{
		if (e.Row.RowType == DataControlRowType.DataRow)
		{
			e.Row.Attributes.Add("onmouseover", "c=this.style.backgroundColor;this.style.backgroundColor='#E7EDFE'");
			e.Row.Attributes.Add("onmouseout", "this.style.backgroundColor=c;");
		}
	}
	protected void UpdateShopProductNum_Click(object sender, EventArgs e)
	{
		this.Page.ClientScript.RegisterStartupScript(this.Page.GetType(), "alert", "<script>alert('更新成功');location.href='Admin_Shop.aspx';</script>", false);
	}
	protected void UpdateShoTemplate_Click(object sender, EventArgs e)
	{
		string fileName = HttpContext.Current.Server.MapPath("~") + "Shop\\Default\\Index.aspx";
		Shop_Shop shop_Shop = new Shop_Shop();
		FileInfo fileInfo = new FileInfo(fileName);
		if (fileInfo.Exists)
		{
			DataTable dataTable = DbHelperSQL.GetDataTable("Select ShopID from HLShop_Shop where ShopStatus=1");
			if (dataTable != null && dataTable.Rows.Count > 0)
			{
				int num = 0;
				for (int i = 0; i < dataTable.Rows.Count; i++)
				{
					string text = HttpContext.Current.Server.MapPath("~") + "Shop\\" + dataTable.Rows[i][0].ToString() + "\\index.aspx";
					FileInfo fileInfo2 = new FileInfo(text);
					try
					{
						if (fileInfo2.Exists)
						{
							fileInfo.CopyTo(text, true);
							num++;
						}
						else
						{
							shop_Shop.CreateShopFile((int)dataTable.Rows[i][0]);
						}
					}
					catch (Exception ex)
					{
						base.Response.Write("<script>alert('更新店铺模板页出错.原因是" + ex.Message + "');history.go(-1);</script>");
						base.Response.End();
					}
				}
				if (num > 0)
				{
					this.Page.ClientScript.RegisterStartupScript(this.Page.GetType(), "alert", "<script>alert('更新成功店铺模板页共" + num.ToString() + "个');history.go(-1);</script>", false);
				}
			}
		}
		this.Page.ClientScript.RegisterStartupScript(this.Page.GetType(), "alert", "<script>alert('店铺母版页不存在,请检查');history.go(-1);</script>");
	}
}
